package org.snail.chat.service.listener;

import com.alibaba.fastjson.JSON;
import lombok.extern.log4j.Log4j;
import org.snail.chat.service.impl.ChainToChatOptionService;
import org.snail.other.bean.GroupDO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.MessageListener;
import javax.jms.TextMessage;

/**
 * 数据库与map中的规则匹配，然后群组及群组人员进行增删改等操作
 */
@Component("chainToChatListener")
@Log4j
public class ChainToChatListener  implements MessageListener {

    @Autowired
    private ChainToChatOptionService chainToChatOptionService;

    @Override
    public void onMessage(Message message) {
        try {
            TextMessage textMessage = (TextMessage) message;
            log.info("=======================进行activemq  Chat存储操作,消息内容：" + textMessage);
            String text = textMessage.getText();
            GroupDO groupDO = JSON.parseObject(text, GroupDO.class);
            log.info("`````````````ghb:groupDO:"+groupDO);
            chainToChatOptionService.doOpiton(groupDO);
        } catch (JMSException e) {
            log.error("钉钉接口保存至部门信息  activemq错误!", e);
        } catch (Exception e) {
            log.error(e);
        }
    }
}
